package com.up.upzl.biz.controller;

import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.up.upzl.biz.bean.SysAccountInSession;
import com.up.upzl.biz.common.Constant;
import com.up.upzl.biz.domain.Area;
import com.up.upzl.biz.domain.Customer;
import com.up.upzl.biz.domain.Customer.EntrustType;
import com.up.upzl.biz.domain.PaiDianRecord;
import com.up.upzl.biz.domain.PaiDianRecord.Status;
import com.up.upzl.biz.domain.Shop;
import com.up.upzl.biz.domain.Shop.CreateType;
import com.up.upzl.biz.domain.Shop.ShopAudit;
import com.up.upzl.biz.domain.Shop.ShopFlow;
import com.up.upzl.biz.domain.Shop.Type;
import com.up.upzl.biz.domain.ShopAdvantage;
import com.up.upzl.biz.domain.ShopBlock;
import com.up.upzl.biz.domain.ShopIssue;
import com.up.upzl.biz.domain.ShopObstruct;
import com.up.upzl.biz.domain.ShopPaper;
import com.up.upzl.biz.domain.ShopSupporting;
import com.up.upzl.biz.domain.ShopTag;
import com.up.upzl.biz.domain.ShopTransfer;
import com.up.upzl.biz.domain.SysAccount;
import com.up.upzl.biz.service.AreaService;
import com.up.upzl.biz.service.CustomerService;
import com.up.upzl.biz.service.PaiDianRecordService;
import com.up.upzl.biz.service.ShopAdvantageService;
import com.up.upzl.biz.service.ShopBlockService;
import com.up.upzl.biz.service.ShopIssueService;
import com.up.upzl.biz.service.ShopObstructService;
import com.up.upzl.biz.service.ShopPaperService;
import com.up.upzl.biz.service.ShopService;
import com.up.upzl.biz.service.ShopSupportingService;
import com.up.upzl.biz.service.ShopTagService;
import com.up.upzl.biz.service.ShopTransferService;
import com.up.upzl.biz.service.SysAccountService;

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;

/**
 * 核铺控制器
 * 
 * @author youke
 *
 */
@Controller
@RequestMapping("shopAudit")
public class ShopAuditController {

	@Autowired
	private ShopService shopService;
	@Autowired
	private ShopTagService shopTagService;
	@Autowired
	private SysAccountService sysAccountService;
	@Autowired
	private ShopSupportingService shopSupportingService;
	@Autowired
	private ShopPaperService shopPaperService;
	@Autowired
	private ShopAdvantageService shopAdvantageService;
	@Autowired
	private ShopIssueService shopIssueService;
	@Autowired
	private ShopObstructService shopObstructService;
	@Autowired
	private ShopBlockService shopBlockService;
	@Autowired
	private ShopTransferService shopTransferService;
	@Autowired
	private AreaService areaService;

	@Autowired
	private PaiDianRecordService paiDianRecordService;
	@Value("${up.site:}")
	private String siteCode;
	
	@Autowired
	private CustomerService customerService;

	@Value("${up.site:}")
	private String site;
	private Logger log = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private HttpSession session;
	final Long initCount = 30000L;

	/**
	 * 数据导入接口及认领插入库方法（单个认领和批量认领）
	 * 
	 * @param ids
	 *            商铺ID集合
	 * @param source
	 *            数据来源
	 * @param city
	 *            地区
	 * @param shopType
	 *            商铺类型
	 * @param sonManageType
	 *            经营业态
	 * @param name
	 *            商铺名称
	 * @param beginTime
	 *            清洗数据时间开始
	 * @param endTime
	 *            清洗数据时间结束
	 * @return 商铺信息
	 */
	@GetMapping("importData")

	public @ResponseBody Map<String, String> importData(Long[] ids, String source, String city, Shop.Type shopType,
			String sonManageType, String name, Date beginTime, Date endTime) {
		Integer count = 0;
		// 请求API
		java.util.stream.Stream.of(ids).forEach(id -> {
			log.info("" + id);
		});
		List<Shop> shops = shopService.fetchByCondition(site, ids, source, city, shopType, sonManageType, name,
				beginTime, endTime);
		// 转换字段
		for (Shop shop : shops) {
			Long id = shop.getId();
			shop.setId(null);
			Long shopCount = shopService.count();
			if (shopCount > 0) {
				Long newShopCount = shopCount + initCount;
				DecimalFormat df = new DecimalFormat("000000");
				String shopNumber = df.format(newShopCount);
				shop.setShopNumber(shopNumber);
				log.info("新生成商铺编号:{}", shopNumber);
			}

			if (!Objects.isNull(shop.getArea()) && !Strings.isNullOrEmpty(shop.getArea().getName())
					&& Objects.isNull(shop.getArea().getId())) {
				Area area = areaService.findByName(shop.getArea().getName());
				if (null == area) {
					area = areaService
							.findByName(shop.getArea().getName().substring(0, shop.getArea().getName().length() - 1));
				}
				if (null == area) {
					area = areaService.findByName("其他");
				}
				if (area != null) {
					shop.setArea(area);
				}
			}

			Long parentId = null;
			if (site.toUpperCase().equals("BJ")) {
				parentId = 36L;
			} else if (site.toUpperCase().equals("TJ")) {
				parentId = 37L;
			} else {
				parentId = 1L;
			}

			if (shop.getArea() == null) {
				List<Area> areas = areaService.findByParentId(parentId);
				shop.setArea(areaService.save(areas.get(0)));
			}
			shop.setCity(areaService.findOne(parentId));
			shop.setShopTags(null);
			// areaService.saveAndFlush(shop.getCity());
			// if (!shop.getShopTags().isEmpty()) {
			// List<ShopTag> shopTags = Lists.newArrayList();
			//
			// shop.getShopTags().forEach(shopTag -> {
			// ShopTag shopTagTemp = shopTagService.findByName(shopTag.getName());
			// shopTags.add(shopTagTemp);
			// });
			// shop.setShopTags(shopTags);
			// }

			// if (!shop.getShopSupportings().isEmpty()) {
			// List<ShopSupporting> shopSupportings = Lists.newArrayList();
			//
			// shop.getShopSupportings().forEach(shopSupporting -> {
			// ShopSupporting shopSupportingTemp =
			// shopSupportingService.findByName(shopSupporting.getName());
			// shopSupportings.add(shopSupportingTemp);
			// });
			// shop.setShopSupportings(shopSupportings);
			// }

			// //经营业态
			// if (!shop.getSonManageType().isEmpty()) {
			// List<ShopBusinessType> shopBusinessTypes = Lists.newArrayList();
			//
			// shop.getManageBusinessTypes().forEach(shopBusinessType -> {
			// ShopBusinessType shopBusinessTypeTemp = shopBusinessTypeService
			// .findByName(shopBusinessType.getName());
			// shopBusinessTypes.add(shopBusinessTypeTemp);
			// });
			// shop.setManageBusinessTypes(shopBusinessTypes);
			// }

			// 适合业态
			// if (!shop.getFitBusinessTypes().isEmpty()) {
			// List<ShopBusinessType> shopBusinessTypes = Lists.newArrayList();
			//
			// shop.getFitBusinessTypes().forEach(shopBusinessType -> {
			// ShopBusinessType shopBusinessTypeTemp = shopBusinessTypeService
			// .findByName(shopBusinessType.getName());
			// shopBusinessTypes.add(shopBusinessTypeTemp);
			// });
			// shop.setFitBusinessTypes(shopBusinessTypes);
			// }
			// 变更状态为待核实
			shop.setShopFlow(ShopFlow.待核实);
			// 认领时间
			shop.setClaimTime(new Date());
			SysAccountInSession sysAccountInSession = (SysAccountInSession) session
					.getAttribute(Constant.USER_IN_SESSION_KEY);
			SysAccount sysAccount = sysAccountService.findOne(sysAccountInSession.getId());
			shop.setVerificationAccount(sysAccount);
			// 认领人
			shop.setUserCode(sysAccountInSession.getAccount());
			// 入库
			shopService.save(shop);
			// 回调
			shopService.notifySucc(site, id);
			count++;
		}
		return ImmutableMap.of("count", count.toString());
	}

	@GetMapping("paiDianImportData")
	public @ResponseBody Map<String, String> paiDianImportData(Long[] ids, String source, String city,
			Shop.Type shopType, String sonManageType, String name, Date beginTime, Date endTime) {

		PaiDianRecord pd = paiDianRecordService.findOne(ids[0]);
		Shop shop = new Shop();

		if (!Objects.isNull(shop.getArea()) && !Strings.isNullOrEmpty(shop.getArea().getName())
				&& Objects.isNull(shop.getArea().getId())) {
			Area area = areaService.findByName(pd.getArea().getName());
			if (null == area) {
				area = areaService
						.findByName(shop.getArea().getName().substring(0, shop.getArea().getName().length() - 1));
			}
			if (null == area) {
				area = areaService.findByName("其他");
			}
			if (area != null) {
				shop.setArea(area);
			}
		}

		Long parentId = null;
		if (site.toUpperCase().equals("BJ")) {
			parentId = 36L;
		} else if (site.toUpperCase().equals("TJ")) {
			parentId = 37L;
		} else {
			parentId = 1L;
		}

		if (pd.getArea() == null) {
			List<Area> areas = areaService.findByParentId(parentId);
			shop.setArea(areaService.save(areas.get(0)));
		}
		shop.setCity(areaService.findOne(parentId));
		shop.setShopTags(null);

		// 变更状态为待认领
		shop.setShopFlow(ShopFlow.待核实);
		// 认领时间
		shop.setClaimTime(new Date());
		SysAccountInSession sysAccountInSession = (SysAccountInSession) session
				.getAttribute(Constant.USER_IN_SESSION_KEY);
		SysAccount sysAccount = sysAccountService.findOne(sysAccountInSession.getId());
		shop.setVerificationAccount(sysAccount);
		// 认领人
		shop.setUserCode(sysAccountInSession.getAccount());
		//手机号
		shop.setPhone(pd.getPhone());
		// 挂载图片到服务器
		List<String> list = new ArrayList<String>();
		String img0 = pd.getImg0();
		String img1 = pd.getImg0();
		String img2 = pd.getImg0();
		String img3 = pd.getImg0();
		list.add(img0);
		list.add(img1);
		list.add(img2);
		list.add(img3);
		try {
			method1(list);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//设置shop imgs
		String shopImg = "";
		for(int i=0;i<list.size();i++){
			shopImg += shopPath(list.get(i))+",";
		}
		String imgs = shopImg.substring(0,shopImg.length()-1);
		shop.setImgs(imgs);
		// 入库
		shopService.save(shop);
		// 回调
		shopService.notifySucc(site, shop.getId());
		// 更新拍店记录数据为“以认领”
		pd.setStatus(Status.已认领);
		paiDianRecordService.save(pd);
		return ImmutableMap.of("count", "1");
	}

	public static final String HOSTNAME = "59.110.226.236";
	public static final String USERNAME = "root";
	public static final String PASSWORD = "up-dev01";

	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

	public void method1(List<String> list) throws IOException {
		// 1, 创建一个连接connection对象
		Connection conn = new Connection(HOSTNAME);
		// 2, 进行连接操作
		conn.connect();
		// 3, 进行连接访问授权验证
		boolean isAuth = conn.authenticateWithPassword(USERNAME, PASSWORD);
		if (isAuth) {
			// 4, 创建一个SCPClient对象
			SCPClient client = new SCPClient(conn);
			for (String str : list) {
				if (!Strings.isNullOrEmpty(str)) {
					client.put(str,
							"/mnt/ueditor/apache-tomcat-8.5.16/webapps/ueditor/upload/" + sdf.format(new Date()));
				}

			}
		}
		conn.close();
	}

	// public static void main(String args[]) {
	// method1(new ArrayList<>());
	// }

	/**
	 * 跳转待认领list页面
	 * 
	 * @return
	 */
	@GetMapping("claimList")
	public String list(CreateType createType, Long city, Long area, Long businessArea, Integer rentType, Type type,
			Long shopBusinessType, String name, String shopNumber, Date beginTime, Date endTime, Date claimBeginTime,
			Date claimEndTime, Date verifyBeginTime, Date verifyEndTime, Date auditBeginTime, Date auditEndTime,
			ShopFlow shopFlow, String verifyName, Pageable page, Model model) {
		SysAccountInSession sysAccountInSession = (SysAccountInSession) session
				.getAttribute(Constant.USER_IN_SESSION_KEY);
		String sysAccount = sysAccountInSession.getAccount();
		//
		verifyName = sysAccount;
		if (shopFlow == null) {
			shopFlow = ShopFlow.待认领;
		}
		Page<Shop> list = null;
		String url = null;
		if (ShopFlow.待核实.equals(shopFlow) || ShopFlow.待认领.equals(shopFlow)) {
			String areaText = null;
			if (shopFlow == ShopFlow.待核实) {
				list = shopService.findByAuditConditions(createType, city, area, businessArea, rentType, type,
						shopBusinessType, name, shopNumber, beginTime, endTime, claimBeginTime, claimEndTime,
						verifyBeginTime, verifyEndTime, auditBeginTime, auditEndTime, shopFlow, verifyName, page,
						sysAccount);
				url = "shopAudit/verifyList";
			} else if (shopFlow == ShopFlow.待认领) {
				if (null != area) {
					Area areaObj = areaService.findOne(area);
					if (null != area) {
						areaText = areaObj.getName();
					}
				}
				// 商铺来源字段不一致 进行了转化
				String source = null;
				if (createType == CreateType.五八同城) {
					source = "58";
				} else if (createType == CreateType.房天下) {
					source = "FANG";
				} else if (createType == CreateType.安居客) {
					source = "ANJUKE";
				} else if (createType == CreateType.乐铺) {
					source = "LEPU";
				} else if (createType == CreateType.赶集) {
					source = "GANJI";
				}
				// 待认领列表数据来源于抓铺宝API接口
				list = shopService.list(null, site, source, areaText, null, null, null, auditBeginTime, auditEndTime,
						page);
				url = "shopAudit/claimList";
			}

		} else if (ShopFlow.待审核.equals(shopFlow)) {
			url = "shopAudit/auditList";
		} else if (ShopFlow.审核已通过.equals(shopFlow)) {
			list = shopService.findByAuditCondition(createType, city, area, businessArea, rentType, type,
					shopBusinessType, name, shopNumber, beginTime, endTime, claimBeginTime, claimEndTime,
					verifyBeginTime, verifyEndTime, auditBeginTime, auditEndTime, ShopAudit.审核已通过, verifyName, page,
					null);
			url = "shopAudit/passList2";
		} else if (ShopFlow.审核未通过.equals(shopFlow)) {
			list = shopService.findByAuditCondition(createType, city, area, businessArea, rentType, type,
					shopBusinessType, name, shopNumber, beginTime, endTime, claimBeginTime, claimEndTime,
					verifyBeginTime, verifyEndTime, auditBeginTime, auditEndTime, ShopAudit.审核未通过, verifyName, page,
					null);
			url = "shopAudit/notPassList2";
		} else {
			url = "shopAudit/claimList";
		}

		model.addAttribute("pageList", list);
		return url;
	}

	/**
	 * 拍店待认领
	 */
	@GetMapping("paidianList")
	public String list(Integer area, Integer businessArea, PaiDianRecord.HuanXian huanXian, String phone,
			String wechatId, Date dateBegin, Date dateEnd, PaiDianRecord.Status status, Pageable page, Model model,
			String huanxian1) {
		if (status == null) {
			status = PaiDianRecord.Status.已通过;
		}
		Page<PaiDianRecord> list = paiDianRecordService.findByCondition(area, businessArea, huanXian, phone, wechatId,
				dateBegin, dateEnd, status, page, huanxian1);

		model.addAttribute("pageList", list);

		Long parentId = null;
		if (siteCode.equals("bj")) {
			parentId = 36L;
		} else if (siteCode.equals("tj")) {
			parentId = 37L;
		} else {
			parentId = 36L;
		}

		List<Area> areas = areaService.findByParentId(parentId);

		model.addAttribute("areas", areas);

		return "shopAudit/paidianList";
	}

	/**
	 * 批量认领（作废）
	 * 
	 * @return
	 */
	@PostMapping("claimAll")
	public @ResponseBody Map<String, String> claimAll(String[] shopIds,
			@SessionAttribute("USER_IN_SESSION_KEY") SysAccountInSession session) {
		Map<String, String> map = new HashMap<>();
		Long id = session.getId();
		Date nowTime = new Date();
		List<Shop> lists = shopService.findByUserAccount(id, nowTime);
		Integer size = lists.size();
		Integer num = shopIds.length;
		if (size > 30) {
			map.put("type", "抱歉，每人每天至多认领30个，您已超出，请明日再来吧");
		} else if ((size + num) > 30) {
			map.put("type", "抱歉，您今天已认领" + size + "个，每人每天至多认领30个，请检查后再来吧");
		} else {
			try {
				List<Shop> shops = shopService.shopIds(site, "ids");
				SysAccount sysAccount = sysAccountService.findOne(id);
				shops.forEach(shop -> {
					shop.setVerificationAccount(sysAccount);
					shop.setClaimTime(new Date());
					shop.setShopAudit(ShopAudit.待核实);
					shop.setShopFlow(ShopFlow.待核实);
				});
				shopService.save(shops);
				map.put("type", "认领成功");
			} catch (Exception e) {
				map.put("type", "认领失败");
			}
		}

		return map;
	}

	/**
	 * 单个认领(作废)
	 * 
	 * @return
	 */
	@PostMapping("claim")
	public @ResponseBody Map<String, String> claimAll(Long shopId,
			@SessionAttribute("USER_IN_SESSION_KEY") SysAccountInSession session) {
		Map<String, String> map = new HashMap<>();
		Long id = session.getId();
		Date nowTime = new Date();
		List<Shop> lists = shopService.findByUserAccount(id, nowTime);
		Integer size = lists.size();
		if (size > 30) {
			map.put("type", "抱歉，每人每天至多认领30个，您已超出，请明日再来吧");
		} else if ((size + 1) > 30) {
			map.put("type", "抱歉，您今天已认领" + size + "个，每人每天至多认领30个，请检查后再来吧");
		} else {
			try {
				Shop shop = shopService.findOne(shopId);
				if (shop != null) {
					shop = new Shop();
				} else {
					map.put("type", "您已认领！！");
					return map;
				}

				SysAccount sysAccount = sysAccountService.findOne(id);
				shop.setVerificationAccount(sysAccount);
				shop.setClaimTime(new Date());
				shop.setShopAudit(ShopAudit.待核实);
				shop.setShopFlow(ShopFlow.待核实);
				shopService.save(shop);
				map.put("type", "认领成功");
			} catch (Exception e) {
				map.put("type", "认领失败");
			}
		}

		return map;
	}

	/**
	 * 跳转到核实页面
	 */
	@GetMapping("verifyAddPage")
	public String verifyAddPage(Long id, Model model) {
		Shop shop = shopService.findOne(id);
		List<ShopAdvantage> shopAdvantage = shopAdvantageService.findAll();
		this.initArrays(model);
		model.addAttribute("entity", shop);
		model.addAttribute("shopAdvantage", shopAdvantage);
		return "shopAudit/verifyAddPage";
	}

	/**
	 * 核铺一级审核提交处理
	 * 
	 * @param id
	 *            商铺标识
	 * @param remark
	 *            拒绝原因 （通过无需填写）
	 * @return
	 */
	@PostMapping("reviewPage")
	public @ResponseBody Map<String, String> verifyShopAudit(Long id, Integer flag, String remark) {
		Shop shop = shopService.findOne(id);
		shop.setAuditTime(new Date());
		if (flag == 0) {
			shop.setRemark(remark);
			shop.setIsImport(0);
			shop.setShopAudit(Shop.ShopAudit.审核未通过);
		} else {
			shop.setIsImport(1);
			shop.setShopAudit(Shop.ShopAudit.审核已通过);
		}
		shopService.save(shop);
		return ImmutableMap.of("status", "ok");
	}

	/**
	 * 跳转待审核list页面
	 * 
	 * @return
	 */
	@GetMapping("auditList")
	public String list(CreateType createType, Long city, Long area, Long businessArea, Integer rentType, Type type,
			Long shopBusinessType, String name, String shopNumber, Date beginTime, Date endTime, Date claimBeginTime,
			Date claimEndTime, Date verifyBeginTime, Date verifyEndTime, Date auditBeginTime, Date auditEndTime,
			ShopAudit shopAudit, String verifyName, Pageable page, Model model) {
		if (shopAudit == null) {
			shopAudit = ShopAudit.待审核;
		}
		if (shopAudit != ShopAudit.待审核) {
			verifyName = ((SysAccountInSession) session.getAttribute(Constant.USER_IN_SESSION_KEY)).getAccount();
		}

		Page<Shop> list = shopService.findByAuditCondition(createType, city, area, businessArea, rentType, type,
				shopBusinessType, name, shopNumber, beginTime, endTime, claimBeginTime, claimEndTime, verifyBeginTime,
				verifyEndTime, auditBeginTime, auditEndTime, shopAudit, verifyName, page, null);
		model.addAttribute("pageList", list);
		if (ShopAudit.审核已通过.equals(shopAudit)) {
			return "shopAudit/passList";
		} else if (ShopAudit.审核未通过.equals(shopAudit)) {
			return "shopAudit/notPassList";
		} else {
			return "shopAudit/auditList";
		}
	}

	/**
	 * 跳转到审核页面
	 */
	@GetMapping("reviewPage")
	public String reviewPage(Long id, Model model) {
		Shop shop = shopService.findOne(id);
		this.initArrays(model);
		model.addAttribute("entity", shop);
		// System.out.println("++++++++++" + shop);
		return "shopAudit/reviewPage";
	}

	/**
	 * 跳转到详情页面
	 */
	@GetMapping("detail")
	public String detail(Long id, Model model) {
		Shop shop = shopService.findOne(id);
		this.initArrays(model);
		model.addAttribute("entity", shop);
		return "shopAudit/detail";
	}

	public void initArrays(Model model) {
		List<ShopTag> shopTags = shopTagService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopSupporting> shopSupportings = shopSupportingService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopPaper> shopPapers = shopPaperService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopAdvantage> shopAdvantages = shopAdvantageService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopIssue> shopIssues = shopIssueService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopObstruct> shopObstructs = shopObstructService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopBlock> shopBlocks = shopBlockService.findAll(new Sort(Direction.DESC, "sort"));
		List<ShopTransfer> shopTransfers = shopTransferService.findAll(new Sort(Direction.DESC, "sort"));

		model.addAttribute("shopTags", shopTags);
		model.addAttribute("shopSupportings", shopSupportings);
		model.addAttribute("shopPapers", shopPapers);
		model.addAttribute("shopAdvantages", shopAdvantages);
		model.addAttribute("shopIssues", shopIssues);
		model.addAttribute("shopObstructs", shopObstructs);
		model.addAttribute("shopBlocks", shopBlocks);
		model.addAttribute("shopTransfers", shopTransfers);
	}
	
	/**
	 * 委托待认领列表
	 */
	@GetMapping("customerList")
	public String customerlist(String account,Customer.EntrustType entrustType,Date dateBegin, Date dateEnd,Pageable page, Model model){
		if(entrustType == null) {
			entrustType = Customer.EntrustType.待认领;
		}
		Page<Customer> list = customerService.findByCondition(account,entrustType, dateBegin, dateEnd, page);
		model.addAttribute("pageList", list);
		return "shopAudit/customerList";
	}
	
	//委托找铺待认领
	@GetMapping("customerImportData")
	public @ResponseBody Map<String, String> customerImportData(Long[] ids, String source, String city, Shop.Type shopType,
			String sonManageType, String name, Date beginTime, Date endTime){
		Customer customer = customerService.findOne(ids[0]);
		Shop shop = new Shop();
		// 变更状态为待认领
		shop.setShopFlow(ShopFlow.待核实);
		shop.setPhone(customer.getAccount());
		// 认领时间
		shop.setClaimTime(new Date());
		SysAccountInSession sysAccountInSession = (SysAccountInSession) session
				.getAttribute(Constant.USER_IN_SESSION_KEY);
		SysAccount sysAccount = sysAccountService.findOne(sysAccountInSession.getId());
		shop.setVerificationAccount(sysAccount);
		// 认领人
		shop.setUserCode(sysAccountInSession.getAccount());
		//入库
		shopService.save(shop);
		//更新委托店铺记录状态为“已认领”
		customer.setEntrustType(EntrustType.已认领);
		customerService.save(customer);
		return ImmutableMap.of("count","1");
	}
	
	public String shopPath(String path) {
		if(Strings.isNullOrEmpty(path)) {return "";}
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
		String str1 = path.substring(path.lastIndexOf("/")+1);
		String str2 = "/upload/image/"+sdf.format(new Date())+"/"+str1;
		return str2;
	}
	
}